﻿using FactoryMonitor.Models;
using FactoryMonitor.UserControls;
using System.ComponentModel;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography.Xml;

namespace FactoryMonitor.ViewModels
{
    public class MainWindowViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;

        private MonitorUC _MonitorUC;

        /// <summary>
        /// 
        /// </summary>
        public MainWindowViewModel()
        {
            EnvironmentList =
            [
                new EnvironmentInfo { Name = "温度(°C)", Value = 25 },
                new EnvironmentInfo { Name = "湿度(%)", Value = 60 },
                new EnvironmentInfo { Name = "光照(Lux)", Value = 1013 },
                new EnvironmentInfo { Name = "噪音(db)", Value = 500 },
                new EnvironmentInfo { Name = "风速(m/s)", Value = 2 },
                new EnvironmentInfo { Name = "PM2.5(m³)", Value = 180 },
                new EnvironmentInfo { Name = "氮气(ppm)", Value = 25 },
            ];

            AlarmList =
            [
                new AlarmModel { No = 1, Message = "设备故障", Time = "2024-06-11 12:12:23", Duration = 11 },
                new AlarmModel { No = 2, Message = "温度报警", Time = "2024-06-12 16:34:30", Duration = 123 },
                new AlarmModel { No = 3, Message = "烟感故障", Time = "2024-06-15 17:23:34", Duration = 24 },
                new AlarmModel { No = 4, Message = "设备故障", Time = "2024-06-16 18:56:23", Duration = 54 },
                new AlarmModel { No = 5, Message = "气压故障", Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Duration = 32 },
            ];

            DeviceList =
            [
                new DeviceModel { Name = "电能(Kw.h)", Value = 53.2 },
                new DeviceModel { Name = "电压(V)", Value = 101.3 },
                new DeviceModel { Name = "电流(A)", Value = 500 },
                new DeviceModel { Name = "压差(kpa)", Value = 20 },
                new DeviceModel { Name = "温度(℃)", Value = 180 },
                new DeviceModel { Name = "振动(mm/s)", Value = 25 },
                new DeviceModel { Name = "转速(r/min)", Value = 34.5 },
                new DeviceModel { Name = "气压(kpa)", Value = 25 },
            ];

            #region 初始化雷达数据 

            RaderList =
            [
                new RaderModel { ItemName = "排烟风机", Value = 90 },
                new RaderModel { ItemName = "客梯", Value = 30.00 },
                new RaderModel { ItemName = "供水机", Value = 34.89 },
                new RaderModel { ItemName = "喷淋水泵", Value = 69.59 },
                new RaderModel { ItemName = "稳压设备", Value = 20 },
            ];

            #endregion

            OutWorkUserList = [
                new OutWorkUserModel{ Name = "李明", Position="销售经理", OutWorkDays = 12},
                new OutWorkUserModel{ Name = "王莉莉", Position="副主管", OutWorkDays = 125},
                new OutWorkUserModel{ Name = "方琴", Position="人事", OutWorkDays = 45},
                new OutWorkUserModel{ Name = "朱小明", Position="开发主管", OutWorkDays = 104},
                new OutWorkUserModel{ Name = "梁新奇", Position="高级顾问", OutWorkDays = 93},
            ];
        }

        public MonitorUC MonitorUC
        {
            get
            {

                _MonitorUC ??= new MonitorUC();
                return _MonitorUC;
            }
            set
            {
                _MonitorUC = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MonitorUC"));
            }
        }

        /// <summary>
        /// 时间
        /// </summary>
        public string NowTime => DateTime.Now.ToString("HH:mm");

        /// <summary>
        /// 时间
        /// </summary>
        public string NowDate => DateTime.Now.ToString("yyyy-MM-dd");

        /// <summary>
        /// 礼拜？
        /// </summary>
        public string CurrWeek
        {
            get
            {
                int idx = (int)DateTime.Now.DayOfWeek;
                string[] weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];

                return weeks[idx];
            }
        }

        #region 计算数据
        /// <summary>
        /// 机台数
        /// </summary>
        private string _machineCount = "0248";

        public string MachineCount
        {
            get { return _machineCount; }
            set
            {
                _machineCount = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MachineCount"));
            }
        }

        /// <summary>
        /// 生产计数
        /// </summary>
        private string _produceCount = "2563";

        public string ProduceCount
        {
            get { return _produceCount; }
            set
            {
                _produceCount = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ProduceCount"));
            }
        }

        /// <summary>
        /// 不良计数
        /// </summary>
        private string _badCount = "0374";

        public string BadCount
        {
            get { return _badCount; }
            set
            {
                _badCount = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BadCount"));
            }
        }
        #endregion

        #region 环境数据

        /// <summary>
        /// 
        /// </summary>
        public List<EnvironmentInfo> _environmentList = new();

        public List<EnvironmentInfo> EnvironmentList
        {
            get { return _environmentList; }
            set
            {
                _environmentList = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("EnvironmentList"));
            }
        }
        #endregion

        #region 报警信息

        private List<AlarmModel> alarmModels = new();

        public List<AlarmModel> AlarmList
        {
            get { return alarmModels; }
            set
            {
                alarmModels = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AlarmList"));
            }
        }

        #endregion


        #region 设备列表

        private List<DeviceModel> deviceList = new();


        public List<DeviceModel> DeviceList
        {
            get { return deviceList; }
            set
            {
                deviceList = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("DeviceList"));
            }
        }

        #endregion



        #region 雷达数据属性
        /// <summary>
        /// 雷达
        /// </summary>
        private List<RaderModel> _RaderList;

        /// <summary>
        /// 雷达
        /// </summary>
        public List<RaderModel> RaderList
        {
            get { return _RaderList; }
            set
            {
                _RaderList = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("RaderList"));
                }
            }
        }

        #endregion

        #region 缺勤列表

        private List<OutWorkUserModel> _outWorkUserList = new();

        public List<OutWorkUserModel> OutWorkUserList
        {
            get { return _outWorkUserList; }
            set {
                
                _outWorkUserList = value;

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("OutWorkUserList"));
            }
        }

        #endregion
    }
}
